'''
3
3 99 87 101
4 87 101 5 87
7 99 101 18 5 135 18 99
2
1 2
1 3
'''

x = int(input())
s_list = []
for i in range(x):
    s = list(map(int, input().split()))
    s_list.append(set(s[1:]))

m = int(input())
for i in range(m):
    a, b = map(int, input().split())
    a, b = s_list[a - 1], s_list[b - 1]
    print(f"{(len(a & b) / len(a | b)) * 100:.2f}%")
